<template>
  <div>
    <treeSelect @parentValue="getValue" :formItem="compConfig" ref="aaa" :formNamePath="formNamePath"></treeSelect>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, watch, computed, nextTick } from "vue";
import treeSelect from "../../formitem/treeSelect/index.vue";
import formItemForm from "./config";
import { useModelStore } from "@/store/modules/model/column";
import { useColumnModel } from "@/components/draggable/hooks/useColumnModel";
import request from "@/api/index";
import { useRoute } from "vue-router";
import getOptions from "@/utils/getRelationOptions";
const props = defineProps({
  element: [],
  formNamePath: [],
});
const aaa = ref();
const compConfig = ref(JSON.parse(JSON.stringify(formItemForm.component.settings)));
useColumnModel(
  compConfig,
  computed(() => props.element)
);

const useModel = useModelStore();
const route: any = useRoute();
interface dataSourceType {
  [propName: string]: any;
}
const treeData = ref<dataSourceType[]>([]);
const getValue = (value: any) => {
  useModel.setData({ param: compConfig.param, value });
};
const fetchChannelChannelTree = async () => {
  let data = await request.fetchChannelChannelTree();
  nextTick(() => {
    let arr: any[] = [
      {
        id: "",
        channelName: "无",
      },
    ];
    console.log(compConfig.value.value, 'compConfig.value.value')
    compConfig.value.value = compConfig.value.value ? compConfig.value.value : '';
    treeData.value = getOptions(route.query.channelId, JSON.parse(JSON.stringify(data))) || [];
    if (treeData.value.length) {
      compConfig.value.options = arr.concat(treeData.value);
    } else {
      compConfig.value.options = arr;
    }

  });
};
const text = () => {
  return 11111;
};
defineExpose({ aaa, text });
onMounted(() => {
  nextTick(() => {
    fetchChannelChannelTree();
  })

});
</script>

<style lang="less" scoped></style>
